//
//  GYStoreSearchMainViewController.m
//  GoodLuck
//
//  Created by apple on 2018/3/15.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYStoreSearchMainViewController.h"
#import "GYStoreResultViewController.h"

@interface GYStoreSearchMainViewController ()<UISearchBarDelegate>

/** 搜索 */
@property (nonatomic, weak) UISearchBar *searchBar;
@end

@implementation GYStoreSearchMainViewController

- (IBAction)allShopBtuClick:(UIButton *)sender {
    GYStoreResultViewController *resultVC = [[GYStoreResultViewController alloc] init];
    resultVC.store_id = self.store_id;
    resultVC.keyworld = @"";
    [self.navigationController pushViewController:resultVC animated:YES];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化
    [self setupUI];
}


- (void)setupUI {
    //1.设置搜索框
    UISearchBar *searchBar = [[UISearchBar alloc] init];
    searchBar.delegate = self;
    searchBar.frame = CGRectMake(0, 0, 130, 40);
    searchBar.backgroundImage = [[UIImage alloc] init];
    UITextField *searchField = [searchBar valueForKey:@"searchField"];
    searchField.layer.borderColor = RGBColor(152, 152, 152).CGColor;
    searchBar.placeholder = @"请输入关键词";
    self.navigationItem.titleView = searchBar;
    self.searchBar = searchBar;
    
    //2.设置导航栏
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"搜索" style:UIBarButtonItemStylePlain target:self action:@selector(seatchBtuClick)];
}

- (void)seatchBtuClick {
    [self.searchBar resignFirstResponder];
    if (self.searchBar.text.length != 0) {
        GYStoreResultViewController *resultVC = [[GYStoreResultViewController alloc] init];
        resultVC.keyworld = self.searchBar.text;
        resultVC.store_id = self.store_id;
        [self.navigationController pushViewController:resultVC animated:YES];
    }
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:NO];
}
@end
